package use;

import swimming.DBUtils;
import swimming.VIPcard;
import swimming.consumption;
import swimming.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class manageruse {
    public List<manager> 搜索man(String input) throws SQLException {
        List<manager> list=new ArrayList<>();
        Connection con= DBUtils.getConnection();
        PreparedStatement st= con.prepareStatement("select * from 管理人 where 账号=?");
        st.setString(1,input);
        ResultSet re=st.executeQuery();
        list=result(con,st,re);
        return list;
    }
    public List<? extends Object> 修改(String input) throws SQLException
    {
        List<manager> list=new ArrayList<>();
        Connection con=DBUtils.getConnection();
        PreparedStatement st= con.prepareStatement("update 管理人 set 系统密码=?");
        st.setString(1,input);
        st.executeUpdate();
        st= con.prepareStatement("select  * from 管理人");
        ResultSet re=st.executeQuery();
        list=result(con,st,re);
        return list;
    }
    public List<manager> result(Connection con,PreparedStatement st,ResultSet re) throws SQLException
    {
        List<manager> list=new ArrayList<>();
        try{
            while(re.next())
            {
                String manme=re.getString("系统密码");
                String permission=re.getString("权限");
                String mnum=re.getString("账号");
                manager ma=new manager(manme,mnum,permission);
                list.add(ma);
            }
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        finally {
            DBUtils.close(con,st,re);
        }
        return list;
    }
}
